# Kexio Project Structure Setup Script
# Author: Kexio Team
# Date: 2025-09-02
# Description: Auto create complete project directory structure

Write-Host "Starting Kexio project structure creation..." -ForegroundColor Green

# Project root directory
$rootDir = Get-Location

Write-Host "Creating frontend directories..." -ForegroundColor Yellow

# 前端目录结构
$frontendDirs = @(
    "frontend/public",
    "frontend/src/api/modules",
    "frontend/src/assets",
    "frontend/src/components",
    "frontend/src/composables",
    "frontend/src/stores/modules",
    "frontend/src/router/guards",
    "frontend/src/router/modules",
    "frontend/src/views/auth",
    "frontend/src/views/dashboard",
    "frontend/src/views/system/user",
    "frontend/src/views/system/role",
    "frontend/src/views/system/permission",
    "frontend/src/utils",
    "frontend/src/types",
    "frontend/src/directives"
)

foreach ($dir in $frontendDirs) {
    $fullPath = Join-Path $rootDir $dir
    if (!(Test-Path $fullPath)) {
        New-Item -ItemType Directory -Path $fullPath -Force | Out-Null
        Write-Host "  Created: $dir" -ForegroundColor Green
    }
}

Write-Host "Creating backend directories..." -ForegroundColor Yellow

# Backend common library directories
$commonDirs = @(
    "backend/kexio-common/src/main/java/com/kexio/common/util",
    "backend/kexio-common/src/main/java/com/kexio/common/dto",
    "backend/kexio-common/src/main/java/com/kexio/common/exception",
    "backend/kexio-common/src/main/java/com/kexio/common/constant",
    "backend/kexio-common/src/main/java/com/kexio/common/enums",
    "backend/kexio-common/src/main/resources",
    "backend/kexio-common/src/test/java/com/kexio/common"
)

foreach ($dir in $commonDirs) {
    $fullPath = Join-Path $rootDir $dir
    if (!(Test-Path $fullPath)) {
        New-Item -ItemType Directory -Path $fullPath -Force | Out-Null
        Write-Host "  Created: $dir" -ForegroundColor Green
    }
}

Write-Host "Creating Core Starter directories..." -ForegroundColor Yellow

# Core Starter directories
$coreDirs = @(
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/security/config",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/security/jwt",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/security/auth",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/security/rbac",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/security/context",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/security/filter",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/security/annotation",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/web/config",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/web/validation",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/web/exception",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/web/response",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/data/config",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/data/domain",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/data/cache/impl",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/data/transaction",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/java/com/kexio/core/properties",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/main/resources/META-INF",
    "backend/kexio-framework/kexio-core-spring-boot-starter/src/test/java/com/kexio/core"
)

foreach ($dir in $coreDirs) {
    $fullPath = Join-Path $rootDir $dir
    if (!(Test-Path $fullPath)) {
        New-Item -ItemType Directory -Path $fullPath -Force | Out-Null
        Write-Host "  Created: $dir" -ForegroundColor Green
    }
}

Write-Host "Creating Dynamic Starter directories..." -ForegroundColor Yellow

# Dynamic Starter directories
$dynamicDirs = @(
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/config",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/datasource/config",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/datasource/service",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/datasource/annotation",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/permission/engine",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/permission/rule",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/permission/service",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/permission/annotation",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/config/service",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/config/repository",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/config/entity",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/config/annotation",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/feature/service",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/feature/annotation",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/java/com/kexio/dynamic/properties",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/main/resources/META-INF",
    "backend/kexio-framework/kexio-dynamic-spring-boot-starter/src/test/java/com/kexio/dynamic"
)

foreach ($dir in $dynamicDirs) {
    $fullPath = Join-Path $rootDir $dir
    if (!(Test-Path $fullPath)) {
        New-Item -ItemType Directory -Path $fullPath -Force | Out-Null
        Write-Host "  Created: $dir" -ForegroundColor Green
    }
}

Write-Host "Creating Enterprise Starter directories..." -ForegroundColor Yellow

# Enterprise Starter directories
$enterpriseDirs = @(
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/config",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/observability/logging",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/observability/logging/aspect",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/observability/logging/annotation",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/observability/metrics",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/observability/tracing",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/observability/health",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/integration/file/impl",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/integration/message",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/integration/event",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/governance/ratelimit",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/governance/circuitbreaker",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/governance/retry",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/cache/distributed",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/cache/monitor",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/cache/warmup",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/java/com/kexio/enterprise/properties",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/main/resources/META-INF",
    "backend/kexio-framework/kexio-enterprise-spring-boot-starter/src/test/java/com/kexio/enterprise"
)

foreach ($dir in $enterpriseDirs) {
    $fullPath = Join-Path $rootDir $dir
    if (!(Test-Path $fullPath)) {
        New-Item -ItemType Directory -Path $fullPath -Force | Out-Null
        Write-Host "  Created: $dir" -ForegroundColor Green
    }
}

Write-Host "Creating application module directories..." -ForegroundColor Yellow

# Application module directories
$appDirs = @(
    "backend/kexio-application/src/main/java/com/kexio",
    "backend/kexio-application/src/main/java/com/kexio/config",
    "backend/kexio-application/src/main/java/com/kexio/modules/auth/controller",
    "backend/kexio-application/src/main/java/com/kexio/modules/auth/service/impl",
    "backend/kexio-application/src/main/java/com/kexio/modules/auth/dto",
    "backend/kexio-application/src/main/java/com/kexio/modules/user/controller",
    "backend/kexio-application/src/main/java/com/kexio/modules/user/service/impl",
    "backend/kexio-application/src/main/java/com/kexio/modules/user/domain/enums",
    "backend/kexio-application/src/main/java/com/kexio/modules/user/repository/impl",
    "backend/kexio-application/src/main/java/com/kexio/modules/user/repository/mapper",
    "backend/kexio-application/src/main/java/com/kexio/modules/user/dto",
    "backend/kexio-application/src/main/java/com/kexio/modules/role/controller",
    "backend/kexio-application/src/main/java/com/kexio/modules/role/service/impl",
    "backend/kexio-application/src/main/java/com/kexio/modules/role/domain",
    "backend/kexio-application/src/main/java/com/kexio/modules/role/repository/impl",
    "backend/kexio-application/src/main/java/com/kexio/modules/role/repository/mapper",
    "backend/kexio-application/src/main/java/com/kexio/modules/role/dto",
    "backend/kexio-application/src/main/java/com/kexio/modules/permission/controller",
    "backend/kexio-application/src/main/java/com/kexio/modules/permission/service/impl",
    "backend/kexio-application/src/main/java/com/kexio/modules/permission/domain",
    "backend/kexio-application/src/main/java/com/kexio/modules/permission/repository/impl",
    "backend/kexio-application/src/main/java/com/kexio/modules/permission/repository/mapper",
    "backend/kexio-application/src/main/java/com/kexio/modules/permission/dto",
    "backend/kexio-application/src/main/resources/mapper",
    "backend/kexio-application/src/main/resources/db/migration",
    "backend/kexio-application/src/test/java/com/kexio"
)

foreach ($dir in $appDirs) {
    $fullPath = Join-Path $rootDir $dir
    if (!(Test-Path $fullPath)) {
        New-Item -ItemType Directory -Path $fullPath -Force | Out-Null
        Write-Host "  Created: $dir" -ForegroundColor Green
    }
}

Write-Host "Creating other directories..." -ForegroundColor Yellow

# Other directories
$otherDirs = @(
    "scripts",
    "docs",
    "docker"
)

foreach ($dir in $otherDirs) {
    $fullPath = Join-Path $rootDir $dir
    if (!(Test-Path $fullPath)) {
        New-Item -ItemType Directory -Path $fullPath -Force | Out-Null
        Write-Host "  Created: $dir" -ForegroundColor Green
    }
}

Write-Host ""
Write-Host "Project directory structure creation completed!" -ForegroundColor Green
Write-Host "Total modules created:" -ForegroundColor Cyan
Write-Host "  * Frontend project (Vue3 + TypeScript)" -ForegroundColor White
Write-Host "  * Backend common library (kexio-common)" -ForegroundColor White
Write-Host "  * Core Starter (basic functions)" -ForegroundColor White
Write-Host "  * Dynamic Starter (dynamic features)" -ForegroundColor White
Write-Host "  * Enterprise Starter (enterprise features)" -ForegroundColor White
Write-Host "  * Application module (business logic)" -ForegroundColor White
Write-Host ""
Write-Host "Next step: Run 'mvn clean compile' to verify project structure" -ForegroundColor Yellow
